﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 31.03.2008
 * Zeit: 20:07
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;

namespace Gamadus.Builder.Ast
{
	public enum AssignSymbol
	{
		Equals,
		AddEquals,
		SubtractEquals,
		MultiplayEquals,
		DivideEquals
	}
	
	/// <summary>
	/// Description of Assignment.
	/// </summary>
	public class Assignment : Statement
	{
		Named m_name;
		string m_op;
		Expression m_expr;
		
		public Assignment(Irony.Compiler.AstNode node, SourceLocation location) : base(node, location)
		{
			m_name = new Named(node.ChildNodes[0], new SourceLocation(location,node.ChildNodes[0].Location));
			m_op = (node.ChildNodes[1] as Irony.Compiler.Token).Text;
			m_expr = Expression.MakeExpression(node.ChildNodes[2], new SourceLocation(location,node.ChildNodes[2].Location));
		}
		
//		AssignSymbol ParseSymbol(Irony.Compiler.AstNode node)
//		{
//			switch((node as Irony.Compiler.Token).Text)
//			{
//				case ":=":
//				case "=":
//					return AssignSymbol.Equals;
//				case "+=":
//					return AssignSymbol.AddEquals;
//				case "-=":
//					return AssignSymbol.SubtractEquals;
//				case "*=":
//					return AssignSymbol.MultiplayEquals;
//				case "/=":
//					return AssignSymbol.DivideEquals;
//				default:
//					throw new ArgumentException("Invalid assignment symbol");
//			}
//		}
		
		public override string ToString()
		{
			return "Assignment: "+m_name.ToString()+" ["+m_op.ToString()+"] "+m_expr.ToString();
		}
		
		public override string Generate()
		{
			return m_name.Generate()+" "+m_op+" "+m_expr.Generate();
		}
		
//		protected internal override MSAst.Expression Generate()
//		{
//			switch(m_symbol)
//			{
//				case AssignSymbol.Equals:
//					return m_name.GenerateAssign(m_expr.Generate());
//				case AssignSymbol.AddEquals:
//					return m_name.GenerateAssign(new Binary(m_name, m_expr, Operator.Add).Generate());
//				case AssignSymbol.SubtractEquals:
//					return m_name.GenerateAssign(new Binary(m_name, m_expr, Operator.Subtract).Generate());
//				case AssignSymbol.MultiplayEquals:
//					return m_name.GenerateAssign(new Binary(m_name, m_expr, Operator.Multiply).Generate());
//				case AssignSymbol.DivideEquals:
//					return m_name.GenerateAssign(new Binary(m_name, m_expr, Operator.Divide).Generate());
//				default:
//					throw new NotImplementedException();
//			}
//        }
	}
}
